{block name="seller_top"}{include file='public/seller_top'/}{/block}
<div class="seller_main">
    <div class="seller_right">
        <div style="padding: 20px;">
            {if isset($store_closed)}
            <div class="alert mt10"> <strong>您的供应商已被关闭,原因是：{$store_closed}。</strong> 请联系系统管理员进行开通!</div>
            {/if}
        </div>
    </div>
</div>
<a id="btn_show_goods_select" class="dssc-btn dssc-btn-green" href="javascript:;"><i></i>添加商品</a>


{block name="seller_main"}

<div class="alert">
    <strong>说明:</strong>
    <input type="hidden" class="live_id" value="{$liveId}">
    <ul>
        <li>因微信规定,直播商品图片有效期只有三天,请留意商品的时间</li>
    </ul>
</div>
<!-- 商品搜索 -->
<div id="div_goods_select" class="div-goods-select" style="display: none;">
    <table class="search-form">
        <tr><th class="w150"><strong>商品名称</strong></th><td class="w160"><input id="search_goods_name" type="text w150" class="text" name="goods_name" value=""/></td>
            <td class="w70 tc"><a href="javascript:void(0);" id="btn_search_goods" class="dssc-btn"/><i class="iconfont">&#xe718;</i>{$Think.lang.ds_search}</a></td><td class="w10"></td><td><p class="hint"></p></td>
        </tr>
    </table>
    <div id="div_goods_search_result" class="search-result"></div>
    <a id="btn_hide_goods_select" class="close" href="javascript:void(0);">X</a> </div>
<table class="dssc-default-table">
    <thead>
        <tr>
            <th class="w10"></th>
            <th class="w50">商品图片</th>
            <th class="w50">商品名称</th>
            <th class="w90">价格</th>
            <th class="w120">价格2</th>
            <!--<th class="w120">{$Think.lang.ds_handle}</th>-->
        </tr>
    </thead>
    <tbody id="xianshi_goods_list">
        <tr id="xianshi_goods_list_norecord" style="display:none">
            <td class="norecord" colspan="20"><div class="warning-option"><i class="iconfont">&#xe64c;</i><span>{$Think.lang.no_record}</span></div></td>
        </tr>
    </tbody>
</table>
<div class="bottom">
    <input type="submit" class="submit" id="submit_back" value="{$Think.lang.ds_back}" onclick="self.location=document.referrer;">
</div>
<div id="dialog_edit_xianshi_goods" class="eject_con" style="display:none;">
    <input id="dialog_xianshigoods_id" type="hidden">
    <dl><dt>{$Think.lang.goods_store_price}：</dt><dd><span id="dialog_edit_goods_price"></span></dd></dl>
    <dl><dt>{$Think.lang.discount_price}：</dt><dd><input id="dialog_edit_xianshi_price" type="text" class="text w70"><em class="add-on"><i class="iconfont">&#xe65c;</i></em>
            <p id="dialog_edit_xianshi_goods_error" style="display:none;"><label for="dialog_edit_xianshi_goods_error" class="error"><i class='iconfont'>&#xe64c;</i>{$Think.lang.discount_price_cannot_empty}</label></p>
    </dl>
    <div class="eject_con">
        <div class="bottom pt10 pb10"><a id="btn_edit_xianshi_goods_submit" class="submit" href="javascript:void(0);">{$Think.lang.ds_submit}</a></div>
    </div>
</div>
<script id="xianshi_goods_list_template" type="text/html">
    <tr class="bd-line">
        <td></td>
        <td><a href="<%=goods_url%>" target="_blank"><img src="<%=coverImgUrl_1%>" alt=""></a></td>
        <td><a href="<%=goods_url%>" target="_blank"><%=name%></a></td>
        <td>{$Think.lang.currency}<span dstype="xianshi_price"><%=price%></span></td>
        <td>{$Think.lang.currency}<span dstype="xianshi_price"><%=price2%></span></td>
      <!--  <td class="dscs-table-handle">
            <span><a dstype="btn_del_xianshi_goods" class="btn-red" data-xianshi-goods-id="<%=id%>" href="javascript:void(0);"><i class="iconfont">&#xe725;</i><p>{$Think.lang.ds_del}</p></a></span>
        </td>-->
    </tr>
</script>

<script src="{$Think.PLUGINS_SITE_ROOT}/template.min.js"></script>
<script type="text/javascript">
        $(document).ready(function () {

            // 当前编辑对象，默认为空
            $edit_item = {};

            //现实商品搜索
            $('#btn_show_goods_select').on('click', function () {
                $('#div_goods_select').show();
            });

            //隐藏商品搜索
            $('#btn_hide_goods_select').on('click', function () {
                $('#div_goods_select').hide();
            });

            //搜索商品
            $('#btn_search_goods').on('click', function () {
                var url = "{:url('live/goods_select')}";
                var datas = $.param({goods_name: $('#search_goods_name').val(),live_id:{$liveId}});
                $('#div_goods_search_result').load(url, datas);
            });
            $('#div_goods_search_result').on('click', 'a.demo', function () {
                $('#div_goods_search_result').load($(this).attr('href'));
                return false;
            });

            //添加限时折扣商品弹出窗口 div_goods_search_result
            $('#div_goods_search_result').on('click', '[dstype="btn_add_xianshi_goods"]', function () {
                $('#dialog_goods_id').val($(this).attr('data-goods-id'));
                $('#dialog_goods_name').text($(this).attr('data-goods-name'));
                $('#dialog_goods_price').text($(this).attr('data-goods-price'));
                $('#dialog_input_goods_price').val($(this).attr('data-goods-price'));
                $('#dialog_goods_img').attr('src', $(this).attr('data-goods-img'));
                $('#dialog_add_xianshi_goods').ds_show_dialog({width: 450, title: '{$Think.lang.promotion_add_goods}'});
                $('#dialog_xianshi_price').val('');
                $('#dialog_add_xianshi_goods_error').hide();
            });


            //删除限时活动商品
            $('#xianshi_goods_list').on('click', '[dstype="btn_del_xianshi_goods"]', function () {
                var $this = $(this);
                layer.confirm('{$Think.lang.ds_ensure_del}', {
                    btn: ['确定', '取消'],
                    title: false,
                }, function () {
                    var xianshigoods_id = $this.attr('data-xianshi-goods-id');
                    $.post("{:url('Sellerpromotionxianshi/xianshi_goods_delete')}",{xianshigoods_id: xianshigoods_id},function (data) {
                                if (data.result) {
                                    $this.parents('tr').hide('slow', function () {
                                        var xianshi_goods_count = $('#xianshi_goods_list').find('.bd-line:visible').length;
                                        if (xianshi_goods_count <= 0) {
                                            $('#xianshi_goods_list_norecord').show();
                                        }
                                    });
																		layer.msg('删除成功');
                                } else {
                                    layer.msg(data.message);
                                }
                            }, 'json');
                });
            });

            //渲染限时折扣商品列表
            xianshi_goods_array = $.parseJSON('{:json_encode($list)}');
            if (xianshi_goods_array.length > 0) {
                var xianshi_goods_list = '';
                $.each(xianshi_goods_array, function (index, xianshi_goods) {
                    xianshi_goods_list += template.render('xianshi_goods_list_template', xianshi_goods);
                });
                $('#xianshi_goods_list').prepend(xianshi_goods_list);
            } else {
                $('#xianshi_goods_list_norecord').show();
            }
        });
       function addGoods(id,name,price,price2,img,goods_id) {
           var live_id = $('.live_id').val();
           var room_id  = {$roomId};
           $.post("{:url('live/addGoods')}",{live_goods_id: id,live_id:live_id,room_id:room_id,goods_id:goods_id},function (data) {
               if (data.result) {
                    if($("#xianshi_goods_list").children("tr").length <2){
                        $('.norecord').hide();
                    }
                   var html = '<tr class="bd-line">\n' +
                       '        <td></td>\n' +
                       '        <td><a href="" target="_blank"><img src=" '+img+'"></a></td>\n' +
                       '        <td><a href="" target="_blank">'+name+'</a></td>\n' +
                       '        <td>￥<span dstype="xianshi_price">'+price+'</span></td>\n' +
                       '        <td>￥<span dstype="xianshi_price">'+price2+'</span></td>\n' +
                      /* '        <td class="dscs-table-handle">\n' +
                       '            <span><a dstype="btn_del_xianshi_goods" class="btn-red" data-goods-id="'+id+'" href="javascript:void(0);"><i class="iconfont"></i><p>删除</p></a></span>\n' +
                       '        </td>\n' +*/
                       '    </tr>';
                   $('#xianshi_goods_list').append(html);
                   $('.li_'+id).remove();
                   layer.msg('添加成功');
               } else {
                   layer.msg(data.message);
               }
           }, 'json');
       }
</script>

{/block}
